package com.meatball.dji.common.mqtt.router

import com.meatball.dji.common.mqtt.enum.MethodEnum
import com.meatball.dji.common.mqtt.handler.device.handler.OsdHandler
import com.meatball.dji.common.mqtt.handler.device.handler.UpdateTopologyHandler
import com.meatball.dji.common.mqtt.handler.request.handler.BindStatusHandler
import com.meatball.dji.common.mqtt.handler.request.handler.LicenseValidatorHandler
import com.meatball.dji.common.mqtt.handler.request.handler.OrganizationBindHandler
import com.meatball.dji.common.mqtt.handler.request.handler.OrganizationGetHandler
import com.meatball.dji.common.mqtt.properties.CloudApiProperties
import org.eclipse.paho.client.mqttv3.MqttClient

/**
 * TODO 创建路由工厂
 *
 * @property mqttClient
 * @property cloudApiProperties
 *
 * @param mqttClient
 * @param cloudApiProperties
 * @constructor 创建路由工厂
 *
 * @author 张翔宇
 * @since 2024年4月22日
 */
class MessageHandlerFactory(
    private val mqttClient: MqttClient,
    private val cloudApiProperties: CloudApiProperties
) {
    fun createHandler(methodName: String): MessageHandler? {
        return when (methodName) {
            MethodEnum.CONFIG.method -> LicenseValidatorHandler(mqttClient, cloudApiProperties)
            MethodEnum.AIRPORT_BIND_STATUS.method -> BindStatusHandler(mqttClient)
            MethodEnum.AIRPORT_ORGANIZATION_GET.method -> OrganizationGetHandler(mqttClient)
            MethodEnum.AIRPORT_ORGANIZATION_BIND.method -> OrganizationBindHandler(mqttClient)
            MethodEnum.UPDATE_TOPOLOGY.method -> UpdateTopologyHandler(mqttClient)
            MethodEnum.OSD.method -> OsdHandler()
            // ...其他的处理器
            else -> null
        }
    }
}